package com.tjshop.android.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tjshop.android.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.tjshop.android.model.tj.json.Banner;
import com.tjshop.android.util.ImageLoaderUtils;

import java.util.List;

/**
 * Created by Administrator on 2014/10/21.
 */
public class BannerAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	List<Banner> cityList;
	private Context mContext;

	public BannerAdapter(Context context, List<Banner> clist,
			LayoutInflater inflater) {
		this.inflater = inflater;
		cityList = clist;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return cityList.size();
	}

	@Override
	public Object getItem(int i) {
		return cityList.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		if (view == null) {
			view = inflater.inflate(
					R.layout.inc_activity_main_fragment_home_categories_item,
					null);
		}
		ImageView img = (ImageView) view
				.findViewById(R.id.fragment_home_categories_item_image);
		String thumbPath = cityList.get(i).getPath();
		ImageLoaderUtils.getInstance(mContext).displayImage(thumbPath, img);
		TextView text = (TextView) view
				.findViewById(R.id.fragment_home_categories_item_text);
		text.setText(cityList.get(i).getAdName());
		return view;
	}
}
